package ru.lukyanets.transmission.client.config;

import javafx.geometry.Dimension2D;
import ru.lukyanets.transmission.client.util.LocalizationUtil;

import com.google.inject.Singleton;
import java.util.Locale;

/**
 * @author slukyanets
 * @noinspection unused
 */
@Singleton
public final class GUIConfig extends Config {
    public static final int MIN_WIDTH = 800;
    public static final int MIN_HEIGHT = 600;

    private static final String NODE = "window";

    private Dimension2D windowSize;
    private boolean maximized;
    private Locale locale;

    public GUIConfig() {
        super(NODE);

        windowSize = new Dimension2D(
                getPreferences().getDouble("width", MIN_WIDTH),
                getPreferences().getDouble("height", MIN_HEIGHT)
        );
        maximized = getPreferences().getBoolean("maximized", false);
        locale = LocalizationUtil.getLocaleByName(getPreferences().get("locale", ""));
    }

    public Dimension2D getWindowSize() {
        return windowSize;
    }

    public void setWindowSize(Dimension2D windowSize) {
        this.windowSize = windowSize;
    }

    public boolean isMaximized() {
        return maximized;
    }

    public void setMaximized(boolean maximized) {
        this.maximized = maximized;
    }

    public Locale getLocale() {
        return locale;
    }

    public void setLocale(Locale locale) {
        this.locale = locale;
    }

    @Override
    public void store() {
        getPreferences().putDouble("width", windowSize.getWidth());
        getPreferences().putDouble("height", windowSize.getHeight());
        getPreferences().putBoolean("maximized", maximized);
        getPreferences().put("locale", locale.toString());
    }
}
